<template>
  <div class="upload-container">
    <el-upload
      :data="dataObj"
      :multiple="false"
      :on-remove="handleRemove"
      :show-file-list="false"
       :file-list="fileList"
       :before-upload='beforeUpload'
      
      :on-success="handleImageSuccess"
      class="image-uploader"
      drag
      action="http://123.57.59.222:8081/api/file/supplier_attachments/upload"
    >
      <!-- <i class="el-icon-upload" /> -->
        <el-button size="mini" type="primary">点击上传</el-button>
      <!-- <div class="el-upload__text">
        点击上传
      </div> -->
    </el-upload>
  
     
  </div>
</template>

<script>
import { upload,getSupplierAttachInfo } from '@/api/supplier' 
import {baseUrl2 }from '@/api/remote-search'

export default {
  name: 'SingleImageUpload3',
  props: {
    value: {
      type: String,
      default: ''
    },
   //  dataObj: { supplierId: '', type: '' }
  },
  data() {
    return {
      showbtns: false,
      fileList:[],//
      tempUrl: '',
      imageUrl:{},
      show_file_list:false,
      dataObj: { supplierId: '', type: '' }
    }
  },
  computed: {
  
  },
  created () {
   this.getList()
  },
 methods: {
      handleClose(){
      this.editDisabled = false;
    },
    handleShowSearch() {
      this.showbtns = !this.showbtns;
    },
    getList(){
     this.fileList=[];
       if(sessionStorage.getItem('supplierId')!=null){
        
         let  supplierId=sessionStorage.getItem('supplierId')
         let type=  this.value
         let data={
           supplierId:supplierId,
           type:this.value
         }
        
        getSupplierAttachInfo(data).then(res=>{
         
          if(res.data.code=='200'){
             this.show_file_list=true;
             let self=this;
             let test=[];
            test=res.data.data;
             test.forEach(item=>{
                self.fileList.push({name:item.fileName,url:baseUrl2+"/api/file/download/"+item.filePath})
             })
            
             
          }
        })
         
      }
      
    },
    emitInput(val) {
      this.$emit('input', val)
    },
     handleRemove(file, fileList) {
       
      },
    handleImageSuccess(file) {
      this.$message.success('上传成功');
      this.$emit('getInfo',sessionStorage.getItem('supplierId'))
        //  this.$parent.getInfo(sessionStorage.getItem('supplierId'));
    },
    
    beforeUpload(file) {
      console.log(file.type)
      if(sessionStorage.getItem('supplierId')!=null){
        const _self = this
          _self._data.dataObj.supplierId = sessionStorage.getItem('supplierId')
          // _self._data.dataObj.type = _self.value
          if(['video/mp4', 'video/ogg', 'video/flv', 'video/avi', 'video/wmv', 'video/rmvb', 'video/mov','video/quicktime'].indexOf(file.type) !='-1'){
             _self._data.dataObj.type =1
          }else if(file.type=='image/jpeg'||file.type=='image/png'){
               _self._data.dataObj.type =2
          }else if(file.type=='audio/mp3'||file.type=='audio/mp4'||file.type=='audio/mpeg'){
            _self._data.dataObj.type =3
          }else if(file.type=='application/pdf'||file.type=='application/docx'||file.type=='application/txt'||file.type=='application/xlxs'||file.type=='application/pptx'){
            _self._data.dataObj.type =4
          }else{
            //this.$message.error("请上传正确的格式附件")
          }
    
      }else{
        this.$message.error('请先保存数据，在上传附件')
      }
      
     
    }
  }
}
</script>

<style lang="scss" scoped>
@import "~@/styles/mixin.scss";
  .el-upload-dragger{
    .el-button{
      float: right;
    margin-right: 3px;
    margin-top: 5px;
    }
  }
.upload-container .el-upload .el-upload-dragger{
  height: 40px;
  border:none
}
.upload-container {
  //  margin-top: -25px;
  // width: 100%;
  float: left;
      // margin-bottom: 18px;
  // position: relative;
  // float: right;
  // height: 30px;
  @include clearfix;
  .image-uploader {
   // width: 35%;
    // float: left;
  }
  .image-preview {
    width: 200px;
    height: 20px;
    border:0;
    position: relative;
   // border: 1px dashed #d9d9d9;
    float: left;
    margin-left: 50px;
    .image-preview-wrapper {
      position: relative;
      width: 100%;
      height: 100%;
     display: block;
    }
    .image-preview-action {
      position: absolute;
      width: 100%;
      height: 100%;
      left: 0;
      top: 0;
      cursor: default;
      text-align: center;
      color: #fff;
      opacity: 0;
      font-size: 20px;
      background-color: rgba(0, 0, 0, .5);
      transition: opacity .3s;
      cursor: pointer;
      text-align: center;
      line-height: 200px;
      .el-icon-delete {
        font-size: 36px;
      }
    }
    &:hover {
      .image-preview-action {
        opacity: 1;
      }
    }
  }
  .image-app-preview {
    width: 320px;
    height: 180px;
    position: relative;
    border: 1px dashed #d9d9d9;
    float: left;
    margin-left: 50px;
    .app-fake-conver {
      height: 44px;
      position: absolute;
      width: 100%; // background: rgba(0, 0, 0, .1);
      text-align: center;
      line-height: 64px;
      color: #fff;
    }
  }
}
</style>
